home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.test;
-
- import sub_arctic.lib.base_interactor;
- import sub_arctic.lib.manager;
- import sub_arctic.output.drawable;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Point;
-
- /** Demo class which displays its own location within a string */
- public class coord_tracker extends base_interactor {
- /* instance variables */
-
- /** Text to show before the coordinate display */
- protected String _tag1 = "";
-
- /** Text to show after the coordinate display */
- protected String _tag2 = "";
-
- /** Text of the coordinate */
- protected String _coord_str = "";
-
-
- /** Font to display in */
- protected Font _drawing_font;
-
- /** Cached metrics of the font */
- protected FontMetrics _metric;
-
- /** Full constructor */
- public coord_tracker(int xv, int yv, String tag_1, String tag_2, Font in_fnt)
- {
- super(xv,yv);
-
- /* set tags from paramters */
- _tag1 = tag_1; _tag2 = tag_2; _coord_str = "?,?";
-
- /* use a default font if none was given */
- if (in_fnt == null) in_fnt = new Font("Helvetica", Font.PLAIN, 24);
-
- /* establish a font and cache metrics object */
- _drawing_font = in_fnt;
- _metric = manager.get_metrics(_drawing_font);
-
- /* establish the size of the object */
- set_intrinsic_h(_metric.getHeight()+4);
- set_intrinsic_w(_metric.stringWidth(_tag1+_coord_str+_tag2)+4);
-
- /* force object to be reconfigured and redrawn */
- damage_self();
- }
-
- /** Constructor with default font */
- public coord_tracker(int xv, int yv, String tag_1, String tag_2)
- {
- this(xv,yv,tag_1,tag_2,null);
- }
-
- /** Constructor with all defaults */
- public coord_tracker()
- {
- this(0,0,"[","]");
- }
-
-
- /** Tell the system that the object determines its own width & height */
- public int intrinsic_constraints() {return W|H;}
-
- /** Recompute object's display string based on its new position & resize */
- public void configure()
- {
- Point global_loc = local_to_global(0,0);
- _coord_str = Integer.toString(global_loc.x) + "," +
- Integer.toString(global_loc.y);
- set_intrinsic_w(_metric.stringWidth(_tag1+_coord_str+_tag2)+4);
- super.configure();
- }
-
- /** Provide drawing behavior for the object */
- protected void draw_self_local(drawable d)
- {
- d.setColor(Color.black);
- d.setFont(_drawing_font);
- d.drawString(_tag1+_coord_str+_tag2, 2, _metric.getAscent()+2);
- }
- };
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-